/*
 * Copyright © 2021 Dowsure
 * https://www.dowsure.com/
 *
 * All rights reserved.
 */

package com.dowsure.apisaas.util;

import java.util.List;
import java.util.Map;

/**
 * API response returned by API call.
 *
 * @param <T> The type of data that is deserialized from response body
 */
public class ApiResponse<T> {

    private Integer code;

    private Map<String, List<String>> headers;

    private T data;

    private String message;

    private String msg;

    private Boolean success;

    /**
     * @param code 返回码
     * @param headers The headers of HTTP response
     * @param msg 信息
     */
    public ApiResponse(int code, Map<String, List<String>> headers, String msg) {
        this(code, headers, null, msg, null);
    }

    /**
     * @param code 返回码
     * @param headers The headers of HTTP response
     * @param data Json数据
     * @param message 信息
     * @param success 请求是否成功
     */
    public ApiResponse(Integer code, Map<String, List<String>> headers, T data, String message, Boolean success) {
        this.code = code;
        this.headers = headers;
        this.data = data;
        this.message = message;
        this.success = success;
    }

    /**
     * @param code 返回码
     * @param headers The headers of HTTP response
     * @param data Json数据
     * @param msg 信息
     */
    public ApiResponse(Integer code, Map<String, List<String>> headers, T data, String msg) {
        this.code = code;
        this.headers = headers;
        this.data = data;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Map<String, List<String>> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, List<String>> headers) {
        this.headers = headers;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }


    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean isSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("ApiResponse{");
        sb.append("code=").append(code);
        sb.append(", headers=").append(headers);
        sb.append(", data=").append(data);
        sb.append(", message='").append(message);
        sb.append(", success='").append(success).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
